import { JSEncrypt } from 'jsencrypt'
import config from '~/config'
import { store } from '../store'
export function setEncrypt (msg) {
  const jsencrypt = new JSEncrypt()
  let PublicKey=store.getters.pubilc;
  PublicKey=`-----BEGIN PUBLIC KEY-----${PublicKey}-----END PUBLIC KEY-----`;
  jsencrypt.setPublicKey(PublicKey)
  return jsencrypt.encrypt(msg)
}

export function localGet (key) {
  const value = window.localStorage.getItem(key)
  try {
    return JSON.parse(window.localStorage.getItem(key))
  } catch (error) {
    return value
  }
}

export function localSet (key, value) {
  window.localStorage.setItem(key, JSON.stringify(value))
}

export function localRemove (key) {
  window.localStorage.removeItem(key)
}

 function addP(s){
   return s < 10 ? '0' + s : s
 }
export function getTimes(time){
  const resDate= time.getFullYear() + '-' + addP((time.getMonth() + 1)) + '-' + addP(time.getDate())
  const resTime = addP(time.getHours()) + ':' + addP(time.getMinutes()) + ':' + addP(time.getSeconds())
  return resDate+' '+resTime
}

// 判断内容是否含有表情字符，现有数据库不支持。
export function hasEmoji (str = '') {
  const reg = /[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]/g;
  return str.match(reg) && str.match(reg).length
}

// 单张图片上传
export const uploadImgServer = config[import.meta.env.MODE].baseUrl+'/common/fileload/uploadImage'
// 多张图片上传
export const uploadImgsServer = config[import.meta.env.MODE].baseUrl+'/common/fileload/uploadImage'
// 视频上传
export const uploadVideoServer = config[import.meta.env.MODE].baseUrl+'/common/fileload/uploadVideoFile'

export const pathMap = {
  login: '登录',
  introduce: '店铺首页',
  dashboard: '大盘数据',
  add: '添加商品',
  glist:'商品列表',
  goodpick:'商品自提点',
  orderlist: '订单列表',
  evalation:'评价管理',
  OrderDetail:'订单详情',
  swiper: '轮播图配置',
  hot: '热销商品配置',
  new: '新品上线配置',
  recommend: '为你推荐配置',
  category: '分类管理',
  level2: '分类二级管理',
  level3: '分类三级管理',
  good: '商品管理',
  guest: '会员管理',
  order: '订单管理',
  order_detail: '订单详情',
  account: '修改账户'
}